{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c17513fc-968a-46b1-9e80-8bc6652da07c",
   "metadata": {},
   "outputs": [],
   "source": [
    "from models import get_my_ar,get_my_qwq\n",
    "from modelscope import AutoModelForCausalLM, AutoTokenizer\n",
    "from langchain_core.prompts import ChatPromptTemplate\n",
    "from langchain_core.output_parsers import StrOutputParser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0706618f-a70a-4a4c-859d-ed3321b257f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "ar_model = get_my_ar()\n",
    "jc_model = get_my_qwq()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9b67dbe9-7031-4601-bf98-4e370e17f025",
   "metadata": {},
   "outputs": [],
   "source": [
    "#音频文件地址\n",
    "audio_file_path = \"gdg_hsh.mp3\"\n",
    "with open(audio_file_path, \"rb\") as audio_file:\n",
    "    response = ar_model.transcriptions(audio_file.read())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d787126c-2a4a-4e1e-acc4-44c922bdbbd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = ChatPromptTemplate.from_messages(\n",
    "    messages=[\n",
    "        (\n",
    "            \"system\", \"\"\"\n",
    "        你是一个安全分析员，请分析用户输入的文本中是否存在危及人身安全的语句！\n",
    "        输出的内容中，首先描述该文本描述的情景，之后罗列危及人身安全的语句，并进行分析。\n",
    "        输出格式为：\n",
    "        {{\n",
    "        \"描述概况\":\"文本描述的情景\",\n",
    "        \"危险因素\":\"罗列危及人身安全的语句，并进行分析\"\n",
    "        }}\n",
    "        请注意：\n",
    "            1，只需要输出最终的字符串即可，不要做任何的解释或说明！\n",
    "            2, 输出结果不要用 ```json 和 ```包裹！！！\n",
    "            3, 你的思考过程不能输出超过100个字。\n",
    "            \n",
    "        \"\"\"),\n",
    "         (\n",
    "            \"human\",\n",
    "            \"\"\"{comment}\"\"\",\n",
    "        )\n",
    "    ]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8973ff53-cbae-4d68-b6b6-ac15dcf3752a",
   "metadata": {},
   "outputs": [],
   "source": [
    "parser = StrOutputParser()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3cd8ec48-9859-44eb-a7a4-364e21eeffa4",
   "metadata": {},
   "outputs": [],
   "source": [
    "chain = prompt | jc_model | parser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "66352a4c-7fa6-452d-a449-9672dd71d0a7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'描述概况: 文本描述了一个人在说相声时的一些幽默情境，其中包括对人的称谓和日常生活的小趣事。\\n危险因素: 无'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chain.invoke(input={\"comment\": response['text']})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7958c298-ad45-4783-b8bb-ec50613bfd1b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
